<template>
	<view class="page">
		<artList :list="list"></artList>
		<view class="lz-margin-top-20 lz-padding-bottom-40" v-if="list.length > 0">
			<u-loadmore :status="status" dashed line />
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
import { getList } from '@/common/http.api.js';
export default {
	data() {
		return {
			list: [],
			status: 'loadmore', //nomore   loading loadmore
			queryForm: {
				pageNum: 1,
				pageSize: 10
			}
		};
	},
	onLoad(option) {
		this.getList();
	},
	onShow() {
		//加载
		if (this.refreshFlag == 1) {
			this.$u.vuex('refreshFlag', 0);
			this.queryForm.pageNum = 1;
			this.status = 'loading';
			this.getList();
		}
	},
	onReachBottom() {
		if (this.status == 'nomore') {
			return false;
		}
		this.queryForm.pageNum++;
		this.status = 'loading';
		this.getList();
	},
	// 下拉刷新
	onPullDownRefresh() {
		this.queryForm.pageNum = 1;
		this.status = 'loading';
		this.getList();
		uni.stopPullDownRefresh(); //刷新数据之后停止刷新效果
	},
	methods: {
		getList() {
			//列表数据
			let data = this.queryForm;
			getList({
				data
			})
				.then((res) => {
					console.log(res, '列表数据');
					uni.hideLoading();
					if (this.queryForm.pageNum > 1) {
						this.list = this.list.concat(res.rows);
					} else {
						this.list = res.rows;
					}
					if (res.total > this.list.length) {
						this.status = 'loadmore';
					} else {
						this.status = 'nomore';
					}
					console.log(this.list, '列表数据');
				})
				.catch(() => {});
		}
	}
};
</script>

<style scoped lang="scss">
	.page{
		// background: rgb(249 249 249);
		background:rgba(249, 249, 248, 1);
		min-height: 95vh;
	}
</style>
